package net.techwatch.guava.collect;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import com.google.common.collect.ForwardingSet;

public class InstrumentedSet<E> extends ForwardingSet<E> {
	
	private HashSet<E> delegate = new HashSet<E>();
	private int count = 0;


	@Override
	protected Set<E> delegate() {
		return delegate;
	}

	@Override
	public boolean add(E element) {
		count++;
		return super.add(element);
	}

	@Override
	public boolean addAll(Collection<? extends E> collection) {
		count += collection.size();
		return super.addAll(collection);
	}

	@Override
	public boolean remove(Object object) {
		count--;
		return super.remove(object);
	}

	@Override
	public boolean removeAll(Collection<?> collection) {
		count -= collection.size();
		return super.removeAll(collection);
	}

	public int count() {
		return this.count;
	}

}
